# Avoid multiple calls to find_package to append duplicated properties to the targets
include_guard()########### VARIABLES #######################################################################
#############################################################################################
set(arrow_FRAMEWORKS_FOUND_RELEASE "") # Will be filled later
conan_find_apple_frameworks(arrow_FRAMEWORKS_FOUND_RELEASE "${arrow_FRAMEWORKS_RELEASE}" "${arrow_FRAMEWORK_DIRS_RELEASE}")

set(arrow_LIBRARIES_TARGETS "") # Will be filled later


######## Create an interface target to contain all the dependencies (frameworks, system and conan deps)
if(NOT TARGET arrow_DEPS_TARGET)
    add_library(arrow_DEPS_TARGET INTERFACE IMPORTED)
endif()

set_property(TARGET arrow_DEPS_TARGET
             PROPERTY INTERFACE_LINK_LIBRARIES
             $<$<CONFIG:Release>:${arrow_FRAMEWORKS_FOUND_RELEASE}>
             $<$<CONFIG:Release>:${arrow_SYSTEM_LIBS_RELEASE}>
             $<$<CONFIG:Release>:boost::boost;jemalloc::jemalloc;re2::re2;thrift::thrift-conan-do-not-use;AWS::aws-sdk-cpp-cognito-identity;AWS::aws-sdk-cpp-core;AWS::aws-sdk-cpp-identity-management;AWS::aws-sdk-cpp-s3;AWS::aws-sdk-cpp-sts;xsimd;zstd::libzstd_static;re2::re2;Arrow::arrow_static>
             APPEND)

####### Find the libraries declared in cpp_info.libs, create an IMPORTED target for each one and link the
####### arrow_DEPS_TARGET to all of them
conan_package_library_targets("${arrow_LIBS_RELEASE}"    # libraries
                              "${arrow_LIB_DIRS_RELEASE}" # package_libdir
                              arrow_DEPS_TARGET
                              arrow_LIBRARIES_TARGETS  # out_libraries_targets
                              "_RELEASE"
                              "arrow")    # package_name

# FIXME: What is the result of this for multi-config? All configs adding themselves to path?
set(CMAKE_MODULE_PATH ${arrow_BUILD_DIRS_RELEASE} ${CMAKE_MODULE_PATH})

########## COMPONENTS TARGET PROPERTIES Release ########################################

    ########## COMPONENT Parquet::parquet_static #############

        set(arrow_Parquet_parquet_static_FRAMEWORKS_FOUND_RELEASE "")
        conan_find_apple_frameworks(arrow_Parquet_parquet_static_FRAMEWORKS_FOUND_RELEASE "${arrow_Parquet_parquet_static_FRAMEWORKS_RELEASE}" "${arrow_Parquet_parquet_static_FRAMEWORK_DIRS_RELEASE}")

        set(arrow_Parquet_parquet_static_LIBRARIES_TARGETS "")

        ######## Create an interface target to contain all the dependencies (frameworks, system and conan deps)
        if(NOT TARGET arrow_Parquet_parquet_static_DEPS_TARGET)
            add_library(arrow_Parquet_parquet_static_DEPS_TARGET INTERFACE IMPORTED)
        endif()

        set_property(TARGET arrow_Parquet_parquet_static_DEPS_TARGET
                     PROPERTY INTERFACE_LINK_LIBRARIES
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_FRAMEWORKS_FOUND_RELEASE}>
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_SYSTEM_LIBS_RELEASE}>
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_DEPENDENCIES_RELEASE}>
                     APPEND)

        ####### Find the libraries declared in cpp_info.component["xxx"].libs,
        ####### create an IMPORTED target for each one and link the 'arrow_Parquet_parquet_static_DEPS_TARGET' to all of them
        conan_package_library_targets("${arrow_Parquet_parquet_static_LIBS_RELEASE}"
                                      "${arrow_Parquet_parquet_static_LIB_DIRS_RELEASE}"
                                      arrow_Parquet_parquet_static_DEPS_TARGET
                                      arrow_Parquet_parquet_static_LIBRARIES_TARGETS
                                      "_RELEASE"
                                      "arrow_Parquet_parquet_static")

        ########## TARGET PROPERTIES #####################################
        set_property(TARGET Parquet::parquet_static
                     PROPERTY INTERFACE_LINK_LIBRARIES
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_OBJECTS_RELEASE}>
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_LIBRARIES_TARGETS}>
                     APPEND)

        if("${arrow_Parquet_parquet_static_LIBS_RELEASE}" STREQUAL "")
            # If the component is not declaring any "cpp_info.components['foo'].libs" the system, frameworks etc are not
            # linked to the imported targets and we need to do it to the global target
            set_property(TARGET Parquet::parquet_static
                         PROPERTY INTERFACE_LINK_LIBRARIES
                         arrow_Parquet_parquet_static_DEPS_TARGET
                         APPEND)
        endif()

        set_property(TARGET Parquet::parquet_static PROPERTY INTERFACE_LINK_OPTIONS
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_LINKER_FLAGS_RELEASE}> APPEND)
        set_property(TARGET Parquet::parquet_static PROPERTY INTERFACE_INCLUDE_DIRECTORIES
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_INCLUDE_DIRS_RELEASE}> APPEND)
        set_property(TARGET Parquet::parquet_static PROPERTY INTERFACE_COMPILE_DEFINITIONS
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_COMPILE_DEFINITIONS_RELEASE}> APPEND)
        set_property(TARGET Parquet::parquet_static PROPERTY INTERFACE_COMPILE_OPTIONS
                     $<$<CONFIG:Release>:${arrow_Parquet_parquet_static_COMPILE_OPTIONS_RELEASE}> APPEND)

    ########## COMPONENT Arrow::arrow_static #############

        set(arrow_Arrow_arrow_static_FRAMEWORKS_FOUND_RELEASE "")
        conan_find_apple_frameworks(arrow_Arrow_arrow_static_FRAMEWORKS_FOUND_RELEASE "${arrow_Arrow_arrow_static_FRAMEWORKS_RELEASE}" "${arrow_Arrow_arrow_static_FRAMEWORK_DIRS_RELEASE}")

        set(arrow_Arrow_arrow_static_LIBRARIES_TARGETS "")

        ######## Create an interface target to contain all the dependencies (frameworks, system and conan deps)
        if(NOT TARGET arrow_Arrow_arrow_static_DEPS_TARGET)
            add_library(arrow_Arrow_arrow_static_DEPS_TARGET INTERFACE IMPORTED)
        endif()

        set_property(TARGET arrow_Arrow_arrow_static_DEPS_TARGET
                     PROPERTY INTERFACE_LINK_LIBRARIES
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_FRAMEWORKS_FOUND_RELEASE}>
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_SYSTEM_LIBS_RELEASE}>
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_DEPENDENCIES_RELEASE}>
                     APPEND)

        ####### Find the libraries declared in cpp_info.component["xxx"].libs,
        ####### create an IMPORTED target for each one and link the 'arrow_Arrow_arrow_static_DEPS_TARGET' to all of them
        conan_package_library_targets("${arrow_Arrow_arrow_static_LIBS_RELEASE}"
                                      "${arrow_Arrow_arrow_static_LIB_DIRS_RELEASE}"
                                      arrow_Arrow_arrow_static_DEPS_TARGET
                                      arrow_Arrow_arrow_static_LIBRARIES_TARGETS
                                      "_RELEASE"
                                      "arrow_Arrow_arrow_static")

        ########## TARGET PROPERTIES #####################################
        set_property(TARGET Arrow::arrow_static
                     PROPERTY INTERFACE_LINK_LIBRARIES
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_OBJECTS_RELEASE}>
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_LIBRARIES_TARGETS}>
                     APPEND)

        if("${arrow_Arrow_arrow_static_LIBS_RELEASE}" STREQUAL "")
            # If the component is not declaring any "cpp_info.components['foo'].libs" the system, frameworks etc are not
            # linked to the imported targets and we need to do it to the global target
            set_property(TARGET Arrow::arrow_static
                         PROPERTY INTERFACE_LINK_LIBRARIES
                         arrow_Arrow_arrow_static_DEPS_TARGET
                         APPEND)
        endif()

        set_property(TARGET Arrow::arrow_static PROPERTY INTERFACE_LINK_OPTIONS
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_LINKER_FLAGS_RELEASE}> APPEND)
        set_property(TARGET Arrow::arrow_static PROPERTY INTERFACE_INCLUDE_DIRECTORIES
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_INCLUDE_DIRS_RELEASE}> APPEND)
        set_property(TARGET Arrow::arrow_static PROPERTY INTERFACE_COMPILE_DEFINITIONS
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_COMPILE_DEFINITIONS_RELEASE}> APPEND)
        set_property(TARGET Arrow::arrow_static PROPERTY INTERFACE_COMPILE_OPTIONS
                     $<$<CONFIG:Release>:${arrow_Arrow_arrow_static_COMPILE_OPTIONS_RELEASE}> APPEND)

    ########## AGGREGATED GLOBAL TARGET WITH THE COMPONENTS #####################
    set_property(TARGET arrow::arrow PROPERTY INTERFACE_LINK_LIBRARIES Parquet::parquet_static APPEND)
    set_property(TARGET arrow::arrow PROPERTY INTERFACE_LINK_LIBRARIES Arrow::arrow_static APPEND)

########## For the modules (FindXXX)
set(arrow_LIBRARIES_RELEASE arrow::arrow)
